package com.geelaro.register.controller;

import com.geelaro.register.domain.dto.UserDto;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
public class IndexController {
	// 路由的跳转 上面的地址跳转界面
	@GetMapping("/")
	public String index() {
		return "index";// 跳转到index.html
	}

	@GetMapping("login")
	public String login(Model model) {
		model.addAttribute("user", new UserDto());
		return "login";// 跳转到login.html
	}

	@GetMapping("/login?error")
	public String loginError(Model model) {
		model.addAttribute("loginError", true);
		return "login";
	}

	// 注册
	@GetMapping("/register")
	public String createUser(Model model) {
		model.addAttribute("user", new UserDto());
		return "register";// 跳转到register.html
	}

	// 每个请求有3个页面
	@RequestMapping("/level1/{id}")
	public String leve1(@PathVariable int id) {
		return "views/level1/" + id;
	}

	@RequestMapping("/level2/{id}")
	public String leve2(@PathVariable int id) {
		return "views/level2/" + id;
	}

	@RequestMapping("/level3/{id}")
	public String leve3(@PathVariable int id) {
		return "views/level3/" + id;
	}
}
